package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.pubinfo.passbook.common.model.dto.open.WiteoffAttchment;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
 * 报账审核附件表
 *
 * @TableName t_witeoff_attchment
 */
@TableName(value = "t_witeoff_attchment")
@Data
@NoArgsConstructor
@ApiModel(value = "TWiteoffAttchment", description = "报账审核资料表,接收前端报账单数据")
public class TWiteoffAttchment implements Serializable {
  /**
   */
  @TableId
  @ApiModelProperty(hidden = true)
  private String id;
  
  /**
   * 审核资料地址
   */
  @ApiModelProperty(value = "审核资料地址")
  private String attchmentAdd;
  
  /**
   * 附件文件名
   */
  @ApiModelProperty(value = "附件文件名")
  private String attchmentName;
  
  /**
   * 附件是否需要归档	  0否,1是;如果不传默认为1
   */
  @ApiModelProperty(value = "附件是否需要归档\t  0否,1是;如果不传默认为1")
  private Byte isFile;
  /**
   * 区分附件，电子签章与电子发票	 0：附件，1：电子签章文件，2;电子发票（不传默认为0）
   */
  @ApiModelProperty(value = "区分附件，电子签章与电子发票\t 0：附件，1：电子签章文件，2;电子发票（不传默认为0）")
  private Byte fileType;
  /**
   * Md5秘钥
   */
  @ApiModelProperty(value = "Md5秘钥")
  private String md5Key;
  
  /**
   * 报账单id
   */
  @ApiModelProperty(hidden = true)
  private String otherSystemMainId;
  
  @TableField(exist = false)
  private static final long serialVersionUID = 1L;
  
  public TWiteoffAttchment(TFileElectronicFtp tFileElectronicFtp) {
    this.attchmentName = tFileElectronicFtp.getName();
    this.fileType = 2;
    this.attchmentAdd = tFileElectronicFtp.getFileRelativePath();
    this.md5Key = tFileElectronicFtp.getMd5Code();
  }
  
  public TWiteoffAttchment(WiteoffAttchment witeoffAttchment) {
    BeanUtils.copyProperties(witeoffAttchment, this);
  }
  
  public TWiteoffAttchment(TFileEnclosureFtp tFileEnclosureFtp) {
    this.attchmentName = tFileEnclosureFtp.getName();
    this.fileType = 0;
    this.attchmentAdd = tFileEnclosureFtp.getHttp();
    //  this.attchmentAdd = attchment.getFileRelativePath();
    // this.md5Key = attchment.getMd5Code();
  }
  
  public static List<TWiteoffAttchment> toList(TFileEnclosureFtp tFileEnclosureFtp) {
    List<TWiteoffAttchment> tWiteoffAttchments = new ArrayList<>();
    TWiteoffAttchment tWiteoffAttchment = new TWiteoffAttchment(tFileEnclosureFtp);
    tWiteoffAttchments.add(tWiteoffAttchment);
    return tWiteoffAttchments;
  }

  public static List<TWiteoffAttchment> toList(List<TFileEnclosureFtp> tFileEnclosureFtps, List<TFileElectronicFtp> tFileElectronicFtps) {
    List<TWiteoffAttchment> tWiteoffAttchments = new ArrayList<>();
    for (TFileEnclosureFtp tFileEnclosureFtp : tFileEnclosureFtps) {
      if (tFileEnclosureFtp != null) {
        TWiteoffAttchment tWiteoffAttchment = new TWiteoffAttchment(tFileEnclosureFtp);
        tWiteoffAttchments.add(tWiteoffAttchment);
      }
    }
    for (TFileElectronicFtp tFileElectronicFtp : tFileElectronicFtps) {
      if (tFileElectronicFtp != null) {
        TWiteoffAttchment tWiteoffAttchment = new TWiteoffAttchment(tFileElectronicFtp);
        tWiteoffAttchments.add(tWiteoffAttchment);
      }
    }
    return tWiteoffAttchments;
  }
}